var fieldname;
var css;
var bgcolor;
var iframename;

function initrtf(name, cssfile, bgcolors, fieldnum, width, height) {
	fieldname=name;
	css=cssfile;
	bgcolor=bgcolors;
	iframename="iframeview"+ fieldnum;
	document.writeln("<iframe width=\""+ width +"\" height=\""+ height +"\" name=\""+ iframename +"\" id=\""+ iframename +"\"></iframe>");
	setIFrameContent();
	document.getElementById(iframename).contentWindow.document.designMode = "on";
}

function setIFrameContent() {
	document.getElementById(iframename).contentWindow.document.open();
	var my_content=document.getElementById(fieldname).value;
	var frameHtml = "<html>\n";
	frameHtml += "<head>\n";
	frameHtml += "<link media=\"all\" type=\"text/css\" href=\""+ css +"\" rel=\"stylesheet\">\n";
	frameHtml += "<style>\n";
	frameHtml += "body {\n";
	frameHtml += "background-color: "+ bgcolor +";\n";
	frameHtml += "margin: 0px;\n";
	frameHtml += "padding: 0px;\n";
	frameHtml += "}\n";
	frameHtml += "</style>\n";
	frameHtml += "</head>\n";
	frameHtml += "<body style=\"background-color:"+ bgcolor +"\">\n";
	frameHtml += my_content + "\n";
	frameHtml += "</body>\n";
	frameHtml += "</html>";
	document.getElementById(iframename).contentWindow.document.write(frameHtml);
	document.getElementById(iframename).contentWindow.document.close();
}

function saveContent() {
	document.getElementById(fieldname).value=document.getElementById(iframename).contentWindow.document.body.innerHTML
	alert(document.getElementById(fieldname).value);
}

function getSelection() {
	var command = 'bold';
	var option = '';
	// if(document.getElementById(iframename).contentWindow.document.queryCommandEnabled('bold')){
	document.getElementById(iframename).contentWindow.document.execCommand('bold', false, '');
	//} else return false;
	document.getElementById(iframename).contentWindow.focus();
}